package cn.yuanqiao.quartz.util;

import com.alibaba.fastjson.serializer.ValueFilter;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class FastjsonDateSerializer implements ValueFilter {
    // 针对LocalDateTime类型的处理
    DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public Object process(Object object, String name, Object value) {
        if(value instanceof Date) {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(value);
        } else if(value instanceof LocalDateTime) {
            return dateTimeFormat.format((LocalDateTime) value);
        }

        return value;
    }
}
